<template>
  <el-submenu
    v-if="menu.list && menu.list.length >= 1"
    :index="menu.menuId + ''"
    :popper-class="'site-sidebar--' + sidebarLayoutSkin + '-popper'">
    <template slot="title">
      <icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
      <span>{{ menu.name }}</span>
    </template>
    <sub-menu
      v-for="item in menu.list"
      :key="item.menuId"
      :menu="item"
      :dynamicMenuRoutes="dynamicMenuRoutes">
    </sub-menu>
  </el-submenu>

    <el-menu-item v-else-if="menu.name!='患者详情'" :index="menu.menuId + ''" @click="gotoRouteHandle(menu)">
      <icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
      <span>{{ menu.name }}</span>
      <!-- 如果是随访管理页面，并且有红点，显示红点 -->
      <span v-if="menu.name=='随访单管理'&&suifangRedHot>0" class="red-hot"></span>
    </el-menu-item>

</template>

<script>
  import {redMixin} from '../mixins/redMixin'
  import SubMenu from './main-sidebar-sub-menu'
  export default {
    name: 'sub-menu',
    mixins: [redMixin],
    props: {
      menu: {
        type: Object,
        required: true
      },
      dynamicMenuRoutes: {
        type: Array,
        required: true
      }
    },
    components: {
      SubMenu
    },
    computed: {
      sidebarLayoutSkin: {
        get () { return this.$store.state.common.sidebarLayoutSkin }
      },
      suifangRedHot:{
        get () { return this.$store.state.common.redPoint.suifangRedHot }
      }
    },
    mounted () {

    },
    methods: {
      // 通过menuId与动态(菜单)路由进行匹配跳转至指定路由
      gotoRouteHandle (menu) {
        var route = this.dynamicMenuRoutes.filter(item => item.meta.menuId === menu.menuId)
        if (route.length >= 1) {
          this.$router.push({ name: route[0].name ,title:route[0].title})
        }
        // this.getRedHot();
      }
    }
  }
</script>
<style lang="scss" scoped>
  .red-hot{
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background-color: red;
    border-radius: 50%;
  }
</style>
